﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.Xml;

namespace NHibernateToSQLMapping.Entity
{
    /// <summary>
    /// 表属性
    /// </summary>
    [Serializable]
    public class TableProperty
    {
        string tableName;
        /// <summary>
        /// 表名
        /// </summary>
        public string TableName
        {
            set
            {
                tableName = value;
            }
            get
            {
                return tableName;
            }
        }

        string tableRemarks;
        /// <summary>
        /// 表注释
        /// </summary>
        public string TableRemarks
        {
            get { return tableRemarks; }
            set { tableRemarks = value; }
        }

        List<FiledProperty> filedProperty = new List<FiledProperty>();
        /// <summary>
        /// 字段属性
        /// </summary>
        public List<FiledProperty> FiledProperty
        {
            get { return filedProperty; }
            set { filedProperty = value; }
        }

        /// <summary>
        /// 是否有主键
        /// </summary>
        public bool IsKey
        {
            get;
            set;
        }
    }

    /// <summary>
    /// 字段属性
    /// </summary>
    [Serializable]
    public class FiledProperty
    {
        static XmlNodeList xnx = null;
        public FiledProperty()
        {
            if (xnx == null)
            {
                XmlDocument xmlDoc = new XmlDocument();
                ResourceManager rmManager = Properties.Resources.ResourceManager;
                string s = rmManager.GetString("filedType");
                xmlDoc.LoadXml(s);
                string strWhere = "/Language/Type";
                xnx = xmlDoc.SelectNodes(strWhere);
            }
        }
        string filedName;
        /// <summary>
        /// 字段名
        /// </summary>
        public string FiledName
        {
            get { return filedName; }
            set { filedName = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string FiledNamePascal { get; set; }

        string filedType;
        /// <summary>
        /// 字段类型
        /// </summary>
        public string FiledType
        {
            get
            {
                foreach (XmlNode partNode in xnx)
                {
                    if (partNode.Attributes["From"].InnerText == filedType.Trim())
                    {
                        filedType = partNode.Attributes["To"].InnerText;
                        break;
                    }
                }
                return filedType;
            }
            set { filedType = value; }
        }

        string filedRemarks;
        /// <summary>
        /// 字段注释
        /// </summary>
        public string FiledRemarks
        {
            get { return filedRemarks; }
            set { filedRemarks = value; }
        }

        /// <summary>
        /// 是否是主键
        /// </summary>
        public string IsPrimarykey
        {
            get;
            set;
        }

        /// <summary>
        /// 是否是自增列
        /// </summary>
        public string IsIdentity
        {
            get;
            set;
        }
    }
}
